/*
* 订单列表
* */

/*
获取所有的订单信息
 */
//统一调用
getOrderList();
function getOrderList() {
    console.log("getOrderList~~~")
    $.ajax({
        url:'/api/order/getList',
        type:'get',
        data:{},
        dataType:'json',
        success:function (data) {
            console.log(data)
            var html = "";
            $.each(data,function (index,item) {

                //遍历当前订单的详情，统计总金额
                var sum = 0;
                $.each(item.orderDetails,function (i,detail) {
                    sum += detail.resultPrice * detail.count
                });
                /*'+(item.status < 4 ? 'order-pay' : '')+'
                '+(item.status < 1 ? 'status-pay' : '')+'
                 '+['等待付款','等待发货','运送中','已收货','退货中','退货中'][item.status]+'
                 '+item.time+' | '+(item.address != null) ? item.address.contack : ''+' | 订单号：'+item.id+'| 在线支付（支付宝快捷支付）
                * */
                html += '<div class="order-box '+(item.status < 4 ? 'order-pay':'')+'">\n' +
                    '\t\t\t\t\t\t\t<div class="order-header">\n' +
                    '\t\t\t\t\t\t\t\t<div class="status '+(item.status < 4 ? 'status-pay':'')+' ">\n' +
                    ['等待付款','等待发货','运送中','已收货','退货中','退货中'][item.status] +
                    '\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t</div>\n' +
                    '\n' +
                    '\t\t\t\t\t\t\t<table class="detail">\n' +
                    '\t\t\t\t\t\t\t\t<thead>\n' +
                    '\t\t\t\t\t\t\t\t\t<tr>\n' +
                    '\t\t\t\t\t\t\t\t\t\t<th class="info">'+item.time+' | '+item.address.college+' '+item.address.major+' '+item.address.detail+' | 订单号：'+item.id+'| 在线支付（支付宝快捷支付）</th>\n' +
                    '\t\t\t\t\t\t\t\t\t\t<th class="money">应付金额： <span>'+sum.toFixed(2)+'</span> 元</th>\n' +
                    '\t\t\t\t\t\t\t\t\t</tr>\n' +
                    '\t\t\t\t\t\t\t\t</thead>\n' +
                    '\t\t\t\t\t\t\t\t<tbody>\n';
                  $.each(item.orderDetails,function (i,detail) {
                      var picture
                      var message
                      var url
                      var price =  detail.resultPrice
                      var count = detail.count
                      if (detail.bookType == '0' ){
                          picture = detail.book.fileUrl[0]
                          message =  detail.book.name+' '+detail.book.author+' '+['新书','二手书'][detail.bookType]
                          url = "/book?id="+detail.book.id;
                      }  else{
                          picture = detail.usedBook.fileUrl[0]
                          message =  detail.usedBook.name+' '+detail.usedBook.author+' '+['新书','二手书'][detail.bookType]
                          url = "/usedBook?id="+detail.usedBook.id;
                      }
                   html += '<tr>'+
                       '\t\t\t\t\t\t\t\t\t\t<td class="goods">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t<div class="goods-box">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t<div class="img">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=""><img src="/upload/'+picture+'" ></a>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t<div class="goods-info">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t\t<p class="name"><a href="'+url+'">'+message+'</a></p>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t\t<p class="price">'+price+'元 x '+count+'</p>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t\t\t\t</td>\n' +
                    '\t\t\t\t\t\t\t\t\t\t<td class="actions">\n' +
                    (item.status == 0 ? '<a class="active" href="/pay/alipay?orderId='+detail.orderId+'&dona_money='+price+'&dona_id='+'111'+'&addressId='+item.addressId+'">立即付款</a>':'') +
                    '\t\t\t\t\t\t\t\t\t\t\t<a href="">订单详情</a>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t<a href="">联系客服</a>\n'
                  });
                  html +=  '\t\t\t\t\t\t\t\t</tbody>\n' +
                    '\t\t\t\t\t\t\t</table>\n' +
                    '\t\t\t\t\t\t</div>';
            });
            $(".order-list").html(html);
        },
        error:function () {

        }
    });
}